/*
 * @Description: 
 * @Version: 1.0
 * @Autor: ziwei
 * @Date: 2021-09-26 15:58:42
 * @LastEditors: ziwei
 * @LastEditTime: 2021-09-26 18:06:33
 */
import { forEachValue } from "../utils";
export default class Module{
  constructor(rawModule){
    this._raw=rawModule;
    this.state=rawModule.state;
    this._children={};
    this.namespaced = rawModule.namespaced;//自己是否已經有命名空間
  }
  //方便扩展
  addChild(key,module){
    this._children[key] = module
  }
  getChild(key){
    return this._children[key]
  }
  forEachChild(fn){
    forEachValue(this._children,fn)
  }
  forEachGetter(fn){
    if(this._raw.getters){
      forEachValue(this._raw.getters,fn);
    }
  }
  forEachMutation(fn){
    if(this._raw.mutations){
      forEachValue(this._raw.mutations,fn);
    }
  }
  forEachAction(fn){
    if(this._raw.actions){
      forEachValue(this._raw.actions,fn);
    }
  }
}